package com.atguigu.yygh.hosp.controller.admin;

import com.atguigu.yygh.common.result.R;
import com.atguigu.yygh.hosp.service.HospitalService;
import com.atguigu.yygh.model.hosp.Hospital;
import com.atguigu.yygh.vo.hosp.HospitalQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

@Api(description = "医院接口")
@RestController
@RequestMapping("/admin/hospital")

public class HosptialController {

    @Autowired
    private HospitalService hospitalService;

//    /admin/hospital/detail/{id}
    @ApiOperation("根据Id获取医院的信息")
    @GetMapping("/detail/{id}")
    public R getHosptetail(@PathVariable String id){
        Hospital hospital = hospitalService.detail(id);
        return  R.ok().data("hospital",hospital);
    }


    @ApiOperation("获取医院分页信息")
    @GetMapping("/{pageNum}/{pageSize}")
    public R getHospitalPage(@PathVariable Integer pageNum, @PathVariable Integer pageSize,
                             HospitalQueryVo hospitalQueryVo){

        Page<Hospital> result =  hospitalService.getHospitalPage(pageNum,pageSize,hospitalQueryVo);
        return  R.ok().data("total",result.getTotalElements()).data("list",result.getContent());
    }

//    修改操作可以用Put请求
    @ApiOperation("根据医院Id修改医院状态")
    @PutMapping("/{id}/{status}")
    public R updateStstus(@PathVariable String id,@PathVariable Integer status){
        hospitalService.updateStatus(id,status);
        return  R.ok();
    }
}
